package rsj.sql.account;

import com.rlyy.aibase.utils.base.MapNode;
import com.rlyy.aibase.utils.base.TableNode;
import rsj.annotation.DynamicSelect;
import rsj.annotation.Param;
import rsj.annotation.Select;
import rsj.annotation.Update;
import rsj.api.account.entity.AccountProduct;
import rsj.service.account.dynamic.AccountProductDynamicStatement;

import java.util.List;

/**
 * 权限
 *
 * @author yuanqinglong
 * @since 2021/7/16 11:38
 */
public interface AccountProductDao {


    /**
     * 添加账户产品
     *
     * @param accountProduct 账户的产品
     */
    @Update(value = "INSERT INTO sys.sys_org_prod (org_id,prod_uid,charge_mode,charge_price,update_tm) " +
            "VALUES (#{orgId},#{prodUid},#{chargeMode},#{chargePrice},#{updateTm})")
    void addAccountProduct(AccountProduct accountProduct);


    /**
     * 获取权限
     *
     * @param orgId org id
     * @return {@link TableNode}
     */
    @Select(value = "SELECT org_id,p.prod_uid,prod_status,charge_mode,charge_price ,prod_id,prod_name FROM sys.sys_org_prod op LEFT JOIN sys.sys_prod p " +
            " ON op.prod_uid = p.prod_uid WHERE org_id = #{orgId} ORDER BY p.prod_uid ")
    TableNode getAccountProducts(@Param(value = "orgId") String orgId);


    /**
     * 更新账户产品
     *
     * @param accountProduct 账户的产品
     */
    @DynamicSelect(type = AccountProductDynamicStatement.class,method = "dynamicUpdate")
    void upsetAccountProduct(AccountProduct accountProduct);


    /**
     * 删除账户产品
     *
     * @param orgIds 机构id
     */
    @DynamicSelect(type = AccountProductDynamicStatement.class,method = "deleteAccountProduct")
    void deleteAccountProduct(@Param(value = "orgId") List<String> orgIds);


    /**
     * 获取机构配置的产品权限
     *
     * @param orgId   机构id
     * @param prodUid 产品编号
     * @return {@link MapNode}
     */
    @Select(value = "SELECT org_id,prod_uid,charge_price FROM sys.sys_org_prod WHERE org_id = #{orgId} AND prod_uid = #{prodUid} ")
    MapNode getAccountProduct(@Param(value = "orgId") String orgId, @Param(value = "prodUid") String prodUid);


}
